package com.edeweiss.community.dao.daoImp;

import com.edeweiss.community.dao.IndexDao;
import com.edeweiss.community.domain.Community;
import com.edeweiss.community.domain.FindHof;
import com.edeweiss.community.domain.Hof;
import com.edeweiss.community.domain.Student;
import com.edeweiss.community.web.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.util.List;

public class IndexDaoImpl implements IndexDao {
    QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
    @Override
    public List<Community> findHonorWall() {
        String sql = "select c.cname,c.ctime,c.cintroduce,c.cimage from community c,honorwall h where h.result = 1 and c.cid = h.community_id";
        List<Community> wall = null;
        try{
           wall = qr.query(sql,new BeanListHandler<Community>(Community.class));
        }catch (Exception e){
            e.printStackTrace();
        }
        return wall;
    }

    @Override
    public List<FindHof> findHallOfFame() {
        String sql = "select s.susername,f.fname,h.experience,h.img from student s,faculty f,hof h where h.result=1 and \n" +
                "h.sid=s.sid and s.sfaculty=f.fid";
        List<FindHof> hofs = null;
        try{
            hofs = qr.query(sql,new BeanListHandler<FindHof>(FindHof.class));
        }catch (Exception e){
            e.printStackTrace();
        }
        return hofs;
    }
}
